package cn.lyn4ever.cataccount.controller;

import cn.lyn4ever.cataccount.entity.Bill;
import cn.lyn4ever.cataccount.entity.Property;
import cn.lyn4ever.cataccount.service.BillService;
import cn.lyn4ever.common.R;
import cn.lyn4ever.common.SecurityParameter;
import com.alibaba.fastjson.JSON;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * (Bill)表控制层
 *
 * @author makejava
 * @since 2019-09-21 16:21:51
 */
@RestController
@RequestMapping("bill")
public class BillController {
    /**
     * 服务对象
     */
    @Resource
    private BillService billService;

    /**
     * 记账
     *
     * @param bill
     * @return
     */
    @RequestMapping("insertOne")
    @SecurityParameter
    public R saveBill(@RequestBody Bill bill) {
        System.out.println(bill.getUserid());
        return billService.saveBill(bill);
    }


    @PostMapping("list")
    @SecurityParameter
    public R list(@RequestBody Bill bill) {
        System.out.println(JSON.toJSONString(bill));
        return billService.list(bill);
    }

    @RequestMapping("getOne")
    @SecurityParameter
    public R getOne(@RequestBody Bill bill) {

        return billService.getOne(bill);
    }

    /**
     * 根据财产查询账单
     *
     * @param property
     * @return
     */
    @RequestMapping("getListByProperty")
    @SecurityParameter
    public R getListByProperty(@RequestBody Property property) {

        return billService.getListByProperty(property);
    }


    /**
     * 删除某一个账单
     *
     * @param bill
     * @return
     */
    @RequestMapping("delOne")
    @SecurityParameter
    public R delOne(@RequestBody Bill bill) {

        return billService.delOne(bill);
    }

    /**
     * 插入转账记录
     *
     * @param bill
     * @return
     */
    @RequestMapping("travel")
    @SecurityParameter
    public R travel(@RequestBody Bill bill) {
        return billService.travel(bill);
    }

}




